package ssh

import (
	"fmt"
	"golang.org/x/crypto/ssh"
	"log"
	"time"
)

func PwdConnect(sshHost, sshUser, sshPassword string, sshPort int) (*ssh.Client, error) {
	config := &ssh.ClientConfig{
		Timeout:         5 * time.Second,
		User:            sshUser,
		Auth:            []ssh.AuthMethod{ssh.Password(sshPassword)},
		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
	}
	addr := fmt.Sprintf("%s:%d", sshHost, sshPort)
	Client, err := ssh.Dial("tcp", addr, config)
	if err != nil {
		log.Fatal("连接到服务器失败", err)
		return nil, err
	}
	return Client, nil
}
